package org.agilelang.editor.syntaxtext.dialogpopup;

/*
 AgileLang - A fourth generation language(http://www.agilelang.org).

 Copyright (C) 2013 Roderick Cusirramos (roderick20@hotmail.com)

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;
import org.agilelang.editor.tool.Util;
import org.agilelang.util.Inflector;

public class DialogBase extends JDialog {

    JPanel centerPanel;
    int NUM = 0;
    String title = "";
    boolean status=false;
    public String tab = "  ";

    public DialogBase(String title, int num) {
        super(new JFrame(), true);
        this.setLocationRelativeTo(null);
        this.title = title;
        NUM = num;
        this.centerPanel = new JPanel(new GridLayout(NUM, 2));
        centerPanel.setBorder(BorderFactory.createEmptyBorder(15, 25, 15, 25));
        this.setIconImage(Util.getIconImage("org/agilelang/util/resources/icon_logo_32.png"));
    }

    public boolean isStatus(){
        return status;
    }
    public final void initUI() {

        JPanel basic = new JPanel();
        basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS));
        add(basic);
        JPanel topPanel = new JPanel(new BorderLayout(0, 0));
        topPanel.setBackground(Color.WHITE);
        topPanel.setMaximumSize(new Dimension(450, 0));
        JLabel hint = new JLabel(this.title);
        hint.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 0));
        topPanel.add(hint);

        ImageIcon icon = new ImageIcon(Util.getIconImage("org/agilelang/util/resources/wand.png"));//new ImageIcon("wand.png");
        JLabel label = new JLabel(icon);
        label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        topPanel.add(label, BorderLayout.EAST);

        JSeparator separator = new JSeparator();
        separator.setForeground(Color.gray);

        topPanel.add(separator, BorderLayout.SOUTH);
        basic.add(topPanel);
        ///---------------------------------------------------------------------
        basic.add(centerPanel);
        //----------------------------------------------------------------------
        JPanel bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT));

        JButton btnAccept = new JButton("Accept");        
        btnAccept.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                accept(evt);
            }            
        });
        JButton btnCancel = new JButton("Close");
        btnCancel.setMnemonic(KeyEvent.VK_C);
        btnCancel.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancel(evt);
            }
        });

        bottom.add(btnAccept);
        bottom.add(btnCancel);
        basic.add(bottom);

        bottom.setMaximumSize(new Dimension(450, 0));

        setTitle(this.title);
        setSize(new Dimension(350, (170 + (NUM - 1) * 25)));//170 el primero - mas 20

        //setResizable(false);
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        setLocationRelativeTo(null);
    }

    public void addLineTxt(String lbl, Component text) {
        javax.swing.JLabel label = new javax.swing.JLabel(lbl+" : ");

        centerPanel.add(label);
        centerPanel.add(text);
    }
    
    public void addSapce() {
        JPanel panel1 = new JPanel(new BorderLayout(0, 0));        
        panel1.setMaximumSize(new Dimension(0, 20));
        JPanel panel2 = new JPanel(new BorderLayout(0, 0));        
        panel2.setMaximumSize(new Dimension(0, 20));

        centerPanel.add(panel1);
        centerPanel.add(panel2);
    }
    
    private void accept(java.awt.event.ActionEvent evt) {
        status = true;
        setVisible(false);
    }

    private void cancel(java.awt.event.ActionEvent evt) {
        status = false;
        setVisible(false);
    }
    
     public String setSingularize(String aLine) {
        return Inflector.getInstance().capitalize(Inflector.getInstance().singularize(aLine));
    }

    public String setPluralize(String aLine) {
        return Inflector.getInstance().capitalize(Inflector.getInstance().pluralize(aLine));
    }

    
}